<template>
	<view class="page">
		<view class="list">
			<view class="item" @click="go('/subpages/set/editPhone')">
				<view class="label">绑定手机号</view>
				<view class="content">{{showMobile}}</view>
				<u-icon name="arrow-right" class="arrow-right" :size="14" color="#C6C6C6"></u-icon>
			</view>
			<view class="item" @click="go('/subpages/set/editPassword')">
				<view class="label">修改密码</view>
				<u-icon name="arrow-right" class="arrow-right" :size="14" color="#C6C6C6"></u-icon>
			</view>
			<!-- #ifdef MP-WEIXIN -->
			<view class="item">
				<view class="label">绑定微信</view>
				<view class="label2" v-if="openid">已绑定</view>
				<view class="label2" @click="bangding"  v-else>点击绑定</view>
				<u-icon name="arrow-right" class="arrow-right" :size="14" color="#C6C6C6"></u-icon>
			</view>
			<!-- #endif -->
			<view class="logout" @click="logout">
				退出登录
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mobile:'',
				showMobile:'',
				openid:''
			}
		},
		onLoad() {},
		onShow() {
			let userInfo = JSON.parse(uni.getStorageSync('userInfo'))
			this.mobile = userInfo.mobile
			this.openid = userInfo.openid
			if(this.mobile){
				this.showMobile = this.mobile.slice(0, 3) + '****' + this.mobile.slice(7);
			}
		},
		methods: {
			go(url){
				uni.navigateTo({
					url:url
				})
			},
			logout(){
				getApp().clearToken()
				uni.reLaunch({
					url:'/subpages/login/login'
				})				
			},
			login() {
				let _this = this;
				return new Promise((resolve, reject) => {
					uni.login({
						provider: 'weixin',
						success: function (loginRes) {
							console.log('login', loginRes);
							resolve(loginRes.code)
						},
						fail(err) {
							reject(err)
						},
					});
				})				
			},
			bangding(){
				var that=this
				uni.showModal({
					title:"绑定微信",
					content:"请确认绑定此微信~",
					success(res) {
						if (res.confirm) {
							var openid=uni.getStorageSync('openid')
							that.rq.getData('user/setOpenid',{openid:openid}).then((res) => {
								if(res.code == 1){
									uni.showToast({
										title:'绑定成功~'
									})
									uni.setStorageSync('userInfo', JSON.stringify(res.data))
									this.openid = openid
								}else{
									uni.showToast({
										title:res.msg
									})
								}
								
							});
							
						} else if (res.cancel) {
						  console.log('用户点击取消');
						}
					}
					
				})
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	.page{
		height: 100vh;
		overflow: hidden;
		
		.list{
			padding: 24rpx;
			
			.item{
				background: #fff;
				height: 92rpx;
				box-sizing: border-box;
				padding: 28rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 20rpx;
				border-radius: 20rpx;
				
				.label{
					font-size: 28rpx;
					color: #333333;
					width: 200rpx;
				}
				.label2{
					width: 400rpx;
					text-align: right;
					font-size: 24rpx;
					font-weight: bold;
					color: #333333;
				}
				.content{
					flex: 1;
					text-align: right;
					margin: 0 10rpx;
				}
			}
		}
		
		.logout{
			margin: 176rpx auto;
			height: 92rpx;
			width: 702rpx;
			border-radius: 100rpx;
			background: #FF5866;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 28rpx;
			color: #FFFFFF;
		}
	}
</style>
